package com.kaoshi.employee.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.alibaba.csp.sentinel.slots.block.flow.FlowException;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kaoshi.common.config.Result;
import com.kaoshi.employee.bean.EmpVo;
import com.kaoshi.employee.bean.Employee;
import com.kaoshi.employee.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("emp")
public class EmpController {
    @Autowired
    private EmployeeService empService;
    //分页+模糊查
    //http://localhost:9000/emp/1/2
    @PostMapping("{page}/{limit}")
    @SentinelResource(value = "abc",blockHandler = "doActionBlockHandler")
    public Result getEmpList(@PathVariable int page,
                             @PathVariable int limit,
                             @RequestBody Employee empVo){
        Page<Employee> pageList=empService.getPageList(page,limit,empVo);
        return Result.ok(pageList);
    }

    public Result doActionBlockHandler(@PathVariable int page,
                                       @PathVariable int limit,
                                       @RequestBody Employee empVo,
                                       BlockException e){
        System.out.println("qqqq");
        return Result.ok("访问过快，请稍后刷新重试");
    }
}
